package com.xinlin.framework.utils;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;

@Component
public class DualJwtGenerator {
    // 独立密钥配置
    @Value("${jwt.system.secret}") private String systemSecret;
    @Value("${jwt.app.secret}") private String appSecret;

    public String generateToken(UserDetails user, String userType) {
        String secret = userType.equals("SYSTEM") ? systemSecret : appSecret;
        return Jwts.builder()
                .setSubject(user.getUsername())
                .claim("userType", userType)
                .signWith(SignatureAlgorithm.HS512, secret)
                .compact();
    }
}
